﻿@model ThaireInvestmentWeb.Models.EditDepositHeaderModel
@{
    ViewBag.Title = "Deposit Header";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script>
    $(document).ready(function () 
    {

        $("#RatingHistory_IssueUpdateDate,#RatingHistory_IssuerUpdateDate,#RatingHistory_GuarantorUpdateDate,#Header_MaturityDate,#Header_InterestPaymentDate").datepicker(
            {
                dateFormat: 'dd/mm/yy',
                isBuddhist: true,
                showOn: 'button',
                showAnim: 'fadeIn',
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                buttonImage: '@Url.Content("~/Content/images/Calendar.png")',
                onSelect: function(dateText, inst) { 
                    if(this.id == "Header_MaturityDate")
                    {
                        getMaturityStatus(dateText);
                    }
                }
            });
        $("#CancelBtn").click(function (event)
        {
            showConfirm(null, CancelBtnAction);
            return false;
        });

    });
    

        
        
        function CancelBtnAction(event)
        {
            window.location.href= 'ManageDeposit';
        }
        function getMaturityStatus(value)
        {
            $.ajax({
                url: "@Url.Action("GetMaturityStatus", "FixedIncome")" + "?maturityDate=" + value,
                type: 'POST',
                success: function(data) {
                    $('#Header_MaturityStatus').val(data.MaturityStatus);
                    return false;
                }
            });
        }
        function getInvolvedType(id)
        {
            $.ajax({
                url: "@Url.Action("GetInvolvedType", "Deposit")" + "?id=" + id,
                type: 'POST',
                success: function(data) {
                    // alert(data.InvolvedPartyTypeCode);
                    $('#InvolvedPartyTypeNO').val(data.InvolvedPartyTypeCode);
                    $('#InvolvedPartyTypeReferance').val(data.InvolvedPartyTypeReference);
                    return false;
                }
            });
        }

    function getCreditAgencyCountry(){
        var rate = $("#IssueRating").val();
        var cred = $("#CreditAgencyIssue").val();
        $.ajax({
            url: "@Url.Action("GetCreditAgencyCountry", "Deposit")",
            data: {rating: rate, credit: cred},
            type: 'POST',
            success: function(data) {
                $('#RatingHistory_IssueCreditAgencyCountry').val(data.CreditAgencyCountry);
                return false;
            }
        });
    }

    function getIssuerCreditAgencyCountry(){
        var rate = $("#IssuerRating").val();
        var cred = $("#CreditAgencyIssuer").val();
        $.ajax({
            url: "@Url.Action("GetCreditAgencyCountry", "Deposit")",
            data: {rating: rate, credit: cred},
            type: 'POST',
            success: function(data) {
                $('#RatingHistory_IssuerCreditAgencyCountry').val(data.CreditAgencyCountry);
                return false;
            }
        });
    }

    function getGuarantorCreditAgencyCountry(){
        var rate = $("#GuarantorRating").val();
        var cred = $("#CreditAgencyIssueGuarantor").val();
        $.ajax({
            url: "@Url.Action("GetCreditAgencyCountry", "Deposit")",
            data: {rating: rate, credit: cred},
            type: 'POST',
            success: function(data) {
                $('#RatingHistory_GuarantorCreditAgencyCountry').val(data.CreditAgencyCountry);
                return false;
            }
        });
    }

        function getBankCode()
        {
            var bank = $("#SelectedBank").val();
            var branch = $("#SelectedBankBranch").val();
            $.ajax({
                url: "@Url.Action("FillBank", "Deposit")",
                data: {bankCode: bank, br: branch},
                dataType: "json",
                type: 'POST',
                success: function(data) {
                    // alert(data.InvolvedPartyTypeCode);
                    $('#Header_BankCode').val(data.BankCode);
                }
            });
        }

        function getBranchName()
        {
            $('#Header_BankCode').val('');
            var abbr = $("#SelectedBank").val();
            $.ajax({
                url: "@Url.Action("GetBranch", "Deposit")",
                data: {bankCode: abbr},
                dataType: "json",
                type: "POST",
                success: function(data) {
                    var items = "";
                    $.each(data, function(i, item) {
                        items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>";
                    });

                    $("#SelectedBankBranch").html(items);
                }
            });
        }
</script>
@*<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>*@

<table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td style="width: 100%;">
            <div class="navi">
                Instrument Type > <a href="@Url.Action("ManageDeposit", "Deposit", new { headerId = @Model.HeaderID })">Deposit at Financial Institutions</a> > Header
          
            </div>
        </td>
    </tr>
</table>

<table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
        <td height="38" align="center" style="width: 100%; text-align: center;">INPUT Deposit at Financial Institutions</td>
    </tr>
</table>

<table width="951" border="0" align="center">
    <tr>
        <td>
            @using (Html.BeginForm("EditDepositHeader", "Deposit", FormMethod.Post, new { id = "mainForm" }))
            {
                @Html.ValidationSummary(true)

                <table width="100%" border="0" align="center" cellspacing="2">
                    <tr>
                        <td width="300" height="31">&nbsp;</td>
                        <td align="right">
                            <div style="text-align: right">Create by : @Model.Header.CreateBY </div>
                        </td>
                        <td width="5">&nbsp;</td>
                        <td width="139" align="right">
                            <div style="text-align: right">Create Time :@Model.Header.CreateDate</div>
                        </td>
                    </tr>
                    <tr>
                        <td width="300" height="31">&nbsp;</td>
                        <td align="right">
                            <div style="text-align: right">Update by : @Model.Header.ModifyBY</div>
                        </td>
                        <td width="5">&nbsp;</td>
                        <td width="139" align="right">
                            <div style="text-align: right">Update Time :@Model.Header.ModifyDate</div>
                        </td>
                    </tr>
                </table>
                <table class="tableform" width="100%" border="5" align="center" cellspacing="2">
                    <tr>
                        <td width="212">
                            <div align="right">Company Name <span class="error">*</span> : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">@Html.DropDownListFor(x => x.SelectedCompany, Model.CompanyList)</td>
                        <td width="188" align="right">
                            <div align="right">Maturity Status:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td width="208">
                            <table width="71%" border="0" cellspacing="1" bgcolor="#000000">
                                <tr>
                                    <td bgcolor="#FFFFFF">@Html.TextBoxFor(model => model.Header.MaturityStatus, new { @readonly = "readonly" })</td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div align="right">Asset Class : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">@Html.DropDownListFor(x => x.SelectedDepositType, Model.DepositTypeList)</td>
                        <td>&nbsp;
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">A/C No. / Voucher No. :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.TextBoxFor(model => model.Header.AccountVoucherNO)
                            @Html.ValidationMessageFor(model => model.Header.AccountVoucherNO)

                        </td>
                        <td>
                            <div align="right">Term (Month) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Header.Term)
                            @Html.ValidationMessageFor(model => model.Header.Term)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Fianancial Instrument Type :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">@Html.DropDownListFor(x => x.SelectedFinanceInstrumentType, Model.FinanceInstrumentTypeList)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Bank Name :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">@Html.DropDownListFor(x => x.SelectedBank, Model.BankList, new { onchange = "getBranchName()" })</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Branch :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td colspan="4">@Html.DropDownListFor(x => x.SelectedBankBranch, Model.BankBranchList, new { onchange = "getBankCode()" })
                            Bank Code : @Html.TextBoxFor(model => model.Header.BankCode, new { @readonly = "readonly" })
                            Symbol : @Html.TextBoxFor(model => model.Header.Symbol, new { @readonly = "readonly" })
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Maturity Date : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.TextBoxFor(model => model.Header.MaturityDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.Header.MaturityDate) })
                            @Html.ValidationMessageFor(model => model.Header.MaturityDate)
                        </td>
                        <td>
                            <div align="right">Interest Payment Date : </div>
                        </td>

                        <td colspan="2">
                            @Html.TextBoxFor(model => model.Header.InterestPaymentDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.Header.InterestPaymentDate) })
                            @Html.ValidationMessageFor(model => model.Header.InterestPaymentDate)
                            @if (Model.UpdateMode)
                            {
                                <text>
                                <input type="button" name="Submit24" value=" History " class="button" onclick="self.location.href = 'ViewInterestPaymentDate?headerId=@Model.HeaderID    ';" >
                                </text>
                            }
                            else
                            {
                                <text>
                                <input type="button" name="Submit24" value=" History " class="button" disabled="disabled">
                                </text>
                            }
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Interest Rate :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">@Html.TextBoxFor(model => model.Header.InterestRate) (%)</td>
                        <td>
                            @if (Model.UpdateMode)
                            {
                                <text>
                                <input type="button" name="Submit24" value=" History " class="button" onclick="self.location.href = 'EditInterestRate?headerId=@Model.HeaderID    ';" >
                                </text>
                            }
                            else
                            {
                                <text>
                                <input type="button" name="Submit24" value=" History " class="button" disabled="disabled">
                                </text>
                            }
                        </td>
                        <td>&nbsp;</td>
                        <td></td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Guarantor :</div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">@Html.TextBoxFor(model => model.Header.Guarantor)</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Liquidity    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td colspan="4">

                            @Html.CheckBoxFor(model => model.IsTierISelected)

                            Tier I&nbsp; 

                            @Html.TextBoxFor(model => model.Header.LiquidityTierIPercent)
                            @Html.ValidationMessageFor(model => model.Header.LiquidityTierIPercent)
                            %
                            <br />
                            @Html.CheckBoxFor(model => model.IsTierIISelected)

                            Tier II&nbsp;

                            @Html.TextBoxFor(model => model.Header.LiquidityTierIIPercent)
                            @Html.ValidationMessageFor(model => model.Header.LiquidityTierIIPercent)

                            %
                            <br />
                            @Html.CheckBoxFor(model => model.IsLowLiquiditySelected)
                            Low Liquidity&nbsp;
                            @Html.TextBoxFor(model => model.Header.LiquidityLowLiquidityPercent)
                            @Html.ValidationMessageFor(model => model.Header.LiquidityLowLiquidityPercent)
                            %
                            <br />
                        </td>
                    </tr>

                    <tr bgcolor="#E8ECFF">
                        <td>
                            <div align="right">Issue Rating : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.DropDownListFor(x => x.IssueRating, Model.IssueRatingList)
                        </td>
                        <td>
                            <div align="right">Credit Agency (Issue) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.CreditAgencyIssue, Model.CreditAgencyIssueList, new { onchange = "getCreditAgencyCountry()" })
                        </td>
                    </tr>

                    <tr bgcolor="#E8ECFF">
                        <td>
                            <div align="right">Issue Rating Update Date : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.TextBoxFor(model => model.RatingHistory.IssueUpdateDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.RatingHistory.IssueUpdateDate) })
                            @Html.ValidationMessageFor(model => model.RatingHistory.IssueUpdateDate)
                        </td>
                        <td>
                            <div align="right">Credit Agency (Issue) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.RatingHistory.IssueCreditAgencyCountry, new { @readonly = "readonly" })
                        </td>
                    </tr>

                    <tr bgcolor="#E8ECFF">
                        <td>
                            <div align="right">Issuer Rating : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.DropDownListFor(x => x.IssuerRating, Model.IssuerRatingList)
                        </td>
                        <td>
                            <div align="right">Credit Agency (Issuer) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.CreditAgencyIssuer, Model.CreditAgencyIssuerList, new { onchange = "getIssuerCreditAgencyCountry()" })
                        </td>
                    </tr>

                    <tr bgcolor="#E8ECFF">
                        <td>
                            <div align="right">Issuer Rating Update Date : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.TextBoxFor(model => model.RatingHistory.IssuerUpdateDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.RatingHistory.IssuerUpdateDate) })
                            @Html.ValidationMessageFor(model => model.RatingHistory.IssuerUpdateDate)
                        </td>
                        <td>
                            <div align="right">Credit Agency (Issuer) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.RatingHistory.IssuerCreditAgencyCountry, new { @readonly = "readonly" })
                        </td>
                    </tr>

                    <tr bgcolor="#E8ECFF">
                        <td>
                            <div align="right">Guarantor Rating : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.DropDownListFor(x => x.GuarantorRating, Model.GuarantorRatingList)
                        </td>
                        <td>
                            <div align="right">Credit Agency (Guarantor) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.CreditAgencyIssueGuarantor, Model.CreditAgencyIssueGuarantorList, new { onchange = "getGuarantorCreditAgencyCountry()" })
                        </td>
                    </tr>

                    <tr bgcolor="#E8ECFF">
                        <td>
                            <div align="right">Guarantor Rating Update Date : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.TextBoxFor(model => model.RatingHistory.GuarantorUpdateDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.RatingHistory.GuarantorUpdateDate) })
                            @Html.ValidationMessageFor(model => model.RatingHistory.GuarantorUpdateDate)
                        </td>
                        <td>
                            <div align="right">Credit Agency (Guarantor) : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.RatingHistory.GuarantorCreditAgencyCountry, new { @readonly = "readonly" })
                        </td>
                    </tr>



                    <tr>
                        <td>
                            <div align="right">Involved Party Type Name    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.DropDownListFor(x => x.SelectedInvolvedPartyType, Model.InvolvedPartyTypeNameList, new { onchange = "getInvolvedType(this.value)", style = "width:100% !important" })
                            &nbsp;</td>
                        <td>
                            <div align="right">Involved Party Type No. : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.InvolvedPartyTypeNO, new { @readonly = "readonly" })
                            @Html.ValidationMessageFor(model => model.InvolvedPartyTypeNO)</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">รหัสอ้างอิง คปภ. (A-E)    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">
                            @Html.TextBoxFor(model => model.InvolvedPartyTypeReferance, new { @readonly = "readonly" })
                            @Html.ValidationMessageFor(model => model.InvolvedPartyTypeReferance)
                        </td>
                        <td>
                            <div align="right">Remain Unit : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Header.RemainUnit)
                            @Html.ValidationMessageFor(model => model.Header.RemainUnit)
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <div align="right"></div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 120px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>

                <table width="95%" border="0" align="center" style="height: 38px">

                    <tr>


                        <td style="height: 38px">
                            <div align="center">
                                <input id="SaveBtn" type="submit" name="SaveBtn" value=" Submit " class="button" need-confirm="true">
                                &nbsp;&nbsp; 
                                <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button">
                                @*&nbsp;&nbsp;
                                <input id="EditBtn" type="button" name="EditBtn" value=" Edit " class="button">*@
                            </div>
                        </td>
                    </tr>

                </table>
                
                            if (Model.UpdateMode)
                            {
                <table width="95%" border="0" align="center">
                    <tr>
                        <td>
                            <div align="center" style="text-align: left">
                                <input type="button" name="PurchaseBtn" value=" Deposit " class="button" onClick="go('@Url.Action("AddDepositTransaction", "Deposit", new { headerId = Model.HeaderID.ToString() })    ');" >
                                &nbsp;&nbsp; 
                                <input type="button" name="Submit42" class="btsub" value="  Withdraw  " onClick="go('@Url.Action("AddWithdrawTransaction", "Deposit", new { headerId = Model.HeaderID.ToString() })    ');" >
                                &nbsp;&nbsp; 
                                <input type="button" name="Submit422" class="btsub" value="  Guarantee  " onClick="go('@Url.Action("AddGuaranteeTransaction", "Deposit", new { headerId = Model.HeaderID.ToString() })    ');" >
                                @*&nbsp;&nbsp;
                                <input type="button" name="Submit422" class="btsub" value=" สิทธิประโยชน์ "/>
                                <input type="button" name="Submit422" class="btsub" value=" สิทธิประโยชน์ " onClick="go('@Url.Action("ManageDepositPrivilege", "Deposit", new { headerId = Model.HeaderID.ToString() })    ');" >*@

                            </div>
                        </td>
                    </tr>
                </table>
                
                            }
                @Html.HiddenFor(x => x.UpdateMode)
                @Html.HiddenFor(x => x.HeaderID)
            }

            <div style="width: 930px; overflow: auto;">
                @if (Model.TransactionAdaters != null)
                {
                    var grid = new WebGrid(source: Model.TransactionAdaters);
                    @grid.GetHtml(tableStyle: "tablelist", headerStyle: "headertable", displayHeader: @Model.TransactionAdaters.Count > 0,
            columns: grid.Columns(
                grid.Column(header: "NO.", format: item => item.WebGrid.Rows.IndexOf(item) + 1, canSort: false),
                grid.Column(columnName: "TransactionType", header: "Transaction Type", canSort: false),
                grid.Column(columnName: "DepositType", header: "Deposit Type", canSort: false),
                grid.Column(columnName: "AccountVoucherNO", header: "A/C / Voucher No.", canSort: false),
                grid.Column(columnName: "BankName", header: "Bank Name", canSort: false),
                grid.Column(columnName: "SettlementDate", header: "Settlement Date", canSort: false),
                grid.Column(columnName: "RefNO", header: "Ref", canSort: false),

 grid.Column(header: "Detail", format:
                        @<text>
                    <input type="image" onClick="go('@item.Link    ');return false;"  src="@Url.Content("~/Content/images/b_edit.gif")"  title="แก้ไข (update)">
                    </text>))
                );
                }
            </div>

            <br>
        </td>
    </tr>
</table>
